﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace sy2_3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txtN.Text))
            {
                MessageBox.Show("请输入数字 n！", "提示");
                return;
            }
            double n;
            if (!double.TryParse(txtN.Text, out n))
            {
                MessageBox.Show("输入的 n 格式不正确，请输入有效的数字！", "错误");
                txtN.Clear();
                txtN.Focus();
                return;
            }
            int mySign;
            if (n < 0)
            {
                mySign = -1;
            }
            else if (n == 0)
            {
                mySign = 0;
            }
            else
            {
                mySign = 1;
            }
            txtMySign.Text = mySign.ToString();
        }
        private void btnClear_Click(object sender, EventArgs e)
        {
            txtN.Clear();
            txtMySign.Clear();
            txtN.Focus();
        }
    }
}
